package eSchool.GUI.Controls;

import javax.swing.table.TableModel;

public class panDetalheDisciplina extends JPanelExtended {

    TableModel tableModel;
    int idDisciplinaColumnIndex = 0;
    int disciplinaColumnIndex = 0;
            
    public panDetalheDisciplina() {
        initComponents();
        setLayoutListaAlunos();
        panDataGrid1.setSearchVisible(false);
        panEditDisciplina1.setEventListner(this);
        panEditDisciplina1.setCodObrigatorio(true);
        panEditDisciplina1.setNomeObrigatorio(true);
    }
        
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panEditDisciplina1 = new eSchool.GUI.Controls.panEditDisciplina();
        jSeparator1 = new javax.swing.JSeparator();
        panDataGrid1 = new eSchool.GUI.Controls.panDataGrid();

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panDataGrid1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
                    .addComponent(panEditDisciplina1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panEditDisciplina1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(panDataGrid1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    private void setLayoutListaAlunos(){
        DataGridColumnIdentifiers dcs = new DataGridColumnIdentifiers();
           
        dcs.add("Ano", "ano", 50);
        dcs.add("Semestre", "semestre", 50);
        dcs.add("Nota", "nota", 50);
        panDataGrid1.setDataGridColumnIdentifiers(dcs);
    }
    
    
    public void setDetailDataSource(TableModel tableModel){
        this.tableModel = tableModel;
        panEditDisciplina1.setDataSource(tableModel);
    }
    
    public void setDetailBindIdDisciplinaIndex(int idDisciplinaColumnIndex){
        this.idDisciplinaColumnIndex = idDisciplinaColumnIndex;
        panEditDisciplina1.setBindIdDisciplinaIndex(idDisciplinaColumnIndex);
    }
    
    public void setDetailBindDisciplinaIndex(int disciplinaColumnIndex){
        this.disciplinaColumnIndex = disciplinaColumnIndex;
        panEditDisciplina1.setBindDisciplinaIndex(disciplinaColumnIndex);
    }
    
    public void setListDataSource(TableModel listTableModel) throws Exception{
       panDataGrid1.setDataSource(listTableModel);
    }
    
    public void setDocentes(TableModel docentesTableModel) throws Exception{
       panEditDisciplina1.setListaDocentes(docentesTableModel);
    }
        
    public void DataBind() throws Exception{
        panEditDisciplina1.DataBind();
        panDataGrid1.DataBind();
    }
    
    @Override
    public void SaveButtonClickEvent(Object Sender, Object obj) {
        tableModel.setValueAt(panEditDisciplina1.getIDDisciplina(), 0, idDisciplinaColumnIndex);
        tableModel.setValueAt(panEditDisciplina1.getDisciplina(), 0, disciplinaColumnIndex);
        tableModel.setValueAt(panEditDisciplina1.getIdDocente() , 0, 2);
        tableModel.setValueAt(panEditDisciplina1.getIdDocenteResponsavel(), 0, 3);
        
        eventListner.SaveButtonClickEvent(this, obj);
    }
    
    public TableModel getDataSource() {
        return this.tableModel;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSeparator jSeparator1;
    private eSchool.GUI.Controls.panDataGrid panDataGrid1;
    private eSchool.GUI.Controls.panEditDisciplina panEditDisciplina1;
    // End of variables declaration//GEN-END:variables
    
}
